<template>
  <default-layout>
    <header-back text="我的办理" slot="header"></header-back>
    <mt-navbar v-model="selected" slot="header" class="tab-header">
      <mt-tab-item id="1">党员之家</mt-tab-item>
      <mt-tab-item id="2">档案管理</mt-tab-item>
      <mt-tab-item id="3">人事代理</mt-tab-item>
      <mt-tab-item id="4">继续教育</mt-tab-item>
    </mt-navbar>
    <div
      v-infinite-scroll="loadMore"
      infinite-scroll-disabled="disabledScroll"
      infinite-scroll-distance="10"
      infinite-scroll-immediate-check="false"
      slot="main"
      class="scroll-view">
      <div class="list">
        <div class="item" @click="handleClick(val)" v-for="(val, key) in list" :key="key">
          <div class="prefix">
            <i class="xffont xf-dangfei" v-if="Number(val.handleType) === 1"></i>
            <i class="xffont xf-renwucundang" v-if="Number(val.handleType) === 2"></i>
            <i class="xffont xf-daili1" v-if="Number(val.handleType) === 3"></i>
            <i class="xffont xf-jiaoyu-copy" v-if="Number(val.handleType) === 4"></i>
          </div>
          <div class="content">
            <div class="tit">{{val.name}}</div>
            <div class="desc">
              <span>{{val.handleDate}}</span>
              <span
                :class="Number(val.statusCode) === 0 ? 'warning' : Number(val.statusCode) === 1 ? 'primary' : 'danger'">
                {{Number(val.statusCode) === 0 ? '未处理' : Number(val.statusCode) === 1 ? '已通过' : '未通过'}}</span>
            </div>
          </div>
        </div>
      </div>
      <loading-text v-if="loading"></loading-text>
      <finish-text v-if="noMore"></finish-text>
      <empty v-if="empty"></empty>
      <yd-backtop></yd-backtop>
    </div>
    <transition name="router" mode="out-in">
      <router-view class="fixed-router" @refresh="refresh"></router-view>
    </transition>
  </default-layout>
</template>
<script>
  import HeaderBack from '../../../components/header-back/header-back.vue'
  import LoadingText from '../../../components/loading-text/loading-text.vue'
  import FinishText from '../../../components/finish-text/finish-text.vue'
  import DefaultLayout from '../../../layouts/default-layout/default-layout'
  import {infinite} from '../../../common/js/mixin'
  import Empty from '../../../components/empty/empty'

  export default {
    components: {
      Empty,
      DefaultLayout,
      FinishText,
      LoadingText,
      HeaderBack},
    computed: { ...infinite },
    data() {
      return {
        selected: 1,
        /* 以下五个参数为上拉加载页面必需的参数 */
        loading: true,
        page: 1,
        size: 10,
        total: 0,
        list: []
        /* 以上五个参数为上拉加载页面必需的参数 */
      }
    },
    methods: {
      loadMore() {
        if (this.page === 1) this.list = []
        this.$post('/admin/person/sapi/person/center/my/transaction/list', {
          page: this.page,
          pageSize: this.size,
          type: this.selected // 查询类型（1：党员之家；2：档案管理；3：人事代理；4：继续教育）
        }, loading => {
          this.loading = loading
        }, false).then(res => {
          /*
          * busiType: 业务类型
          * 党员活动报名(录入后就完成，无后续动作) 2
          * 党组织关系转入(录入后就完成，无后续动作) 3
          * 申请商调函（审核通过后，下载商调函） 4
          * 档案转出（材料预审相同） 5
          * 档案借出（查询该功能对应的状态查询） 6
          * 开具证明（材料预审相同） 8
          * 省医疗保险办理 10
          * 职称申报（有审核状态，后续没有动作） 11
          * 户籍关系转入 12
          * 市养老、医疗保险办理 13
          * 养老缴费基数变更(无后续动作) 14
          * 户籍关系转出 15
          * 办理合格证明 17
          * 继续教育报名 18
          * */
          this.list = this.list.concat(res.data.dataList)
          this.total = res.data.pageBean.totalCount
          this.page++
        })
      },
      handleClick(val) {
        this.$router.push({
          name: 'myApplyActivitySuccess',
          query: {
            status: val.statusCode,
            title: encodeURIComponent(val.name || ''),
            handleType: val.handleType,
            id: val.ID,
            busiType: val.busiType
          }
        })
      },
      refresh() {
        this.page = 1
        this.loadMore()
      }
    },
    created() {
      this.selected = String(this.$route.params.id)
      this.loadMore()
      this.$watch('selected', () => {
        setTimeout(() => {
          this.page = 1
          this.loadMore()
        }, 20)
      })
    }
  }
</script>
<style scoped lang="scss">
  @import "../../../common/style/variable";
  .list{
    background: #fff;
    margin: .15rem 0 0 0;
  }
  .item{
    display: flex;
    align-items: center;
    padding: .2rem;
    @include active;
    .content{
      display: flex;
      flex-direction: column;
      padding: 0 0 0 .2rem;
      flex: 1;
      width: 80%;
      .tit{
        font-size: .32rem;
        padding: 0 0 .1rem 0;
        @include ellipsis;
        width: 100%;
      }
      .desc{
        color: #666;
        display: flex;
        align-items: center;
        justify-content: space-between;
      }
    }
    &:not(:last-child){
      border-bottom: 1px solid #ededed;
    }
  }
  .tab-header{
    border-bottom: 1px solid #ededed;
  }
  .xf-dangfei{
    color: #e87445;
    font-size: .7rem;
  }
  .xf-renwucundang{
    color: #2e71c9;
    font-size: .7rem;
  }
  .xf-daili1{
    color: #4fb4ae;
    font-size: .7rem;
  }
  .xf-jiaoyu-copy{
    color: #f2ba46;
    font-size: .7rem;
  }
  .primary{
    color: $primary;
  }
  .warning{
    color: #666;
  }
  .danger{
    color: $danger;
  }
</style>
